package com.linjiahao.servicebase.exception;

import com.linjiahao.servicebase.common.ResultMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName GlobalExceptionHandler
 * @Description: 全局异常结果自定义返回处理器
 * @Author linjiahao
 * @Date 30/12/2021
 **/
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResultMap error(Exception e) {
        log.error(e.getMessage());
        return ResultMap.error();
    }

    @ExceptionHandler(WebChatException.class)
    @ResponseBody
    public ResultMap error(WebChatException e) {
        e.printStackTrace();
        return ResultMap.error().message(e.getMsg()).code(e.getCode());
    }
}
